/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.folha.dao;

import br.com.folha.entity.Grupo;
import br.com.folha.utilidades.HibernateUtil;
import java.io.Serializable;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @author marceloml
 */
public class GrupoDao implements Serializable{
    
    private static final long serialVersionUID = 1L;
    
    @Autowired
    private SessionFactory sessionFactory;
    
    public List<Grupo> listaGrupo(Object t) {
        Session sessao = HibernateUtil.getSessionFactory();
        Criteria criteria = sessao.createCriteria(t.getClass()).add(Restrictions.ne("id", 1));          
        List lista = criteria.list();
        sessao.close();
        return lista;      
    }
    
    public Grupo getById(int id)
    { 
       Session sessao = HibernateUtil.getSessionFactory();
       Query query = sessao.createQuery("FROM Grupo WHERE id = :id");               
       query.setParameter("id", id);        

       return (Grupo) query.uniqueResult();
    }          
    
}
